package com.zym.community.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration
@EnableSwagger2  // 开启swagger2
public class SwaggerConfig {

    // 一个Docket实例相当于一个swagger分组
    @Bean
    public Docket docket(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("朱一鸣的分组")
                .select()
                // 扫描指定包下的接口
                .apis(RequestHandlerSelectors.basePackage("com.zym.community.controller"))
                .build();
    }

    // 配置swagger信息-apiInfo
    private ApiInfo apiInfo(){
        // contact-作者信息
        Contact contact = new Contact("朱一鸣", "https://blog.csdn.net/qq_42804736", "691639910@qq.com");

        return new ApiInfo("朱一鸣的swagger接口文档",
                            "在这个什么都善变的世界，我想和你看一看永远。",
                            "1.0",
                            "https://blog.csdn.net/qq_42804736",
                            contact,
                            "Apache 2.0",
                            "http://www.apache.org/licenses/LICENSE-2.0",
                            new ArrayList());
    }
}
